package com.example.ticket.controller;

import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/admin")
public class AdminController {
/*
    @GetMapping("/test")
    public String test(Model model){
        SecurityContext context= SecurityContextHolder.getContext();
        System.out.println("userDetails:"+context);
        Authentication authentication=context.getAuthentication();
        UserDetails principal=(UserDetails)authentication.getPrincipal();
        model.addAttribute("username",principal.getUsername());
        return "/pages/index";
    }
*/

/*
    @GetMapping("/head")
    public String head(){
        return "/fragment/head";
    }
*/

/*    @GetMapping("/foot")
    public String foot(){
        return "/fragment/foot";
    }

    @GetMapping("/go")
    public String gogogo(){return "/pages/table";}

    @GetMapping("/left")
    public String leftmenu(){return "/fragment/left-menu";}*/
    String prefix="admin";

    @GetMapping("/userList")
    public String userList(Model model){
        SecurityContext context= SecurityContextHolder.getContext();
        System.out.println("userDetails:"+context);
        Authentication authentication=context.getAuthentication();
        UserDetails principal=(UserDetails)authentication.getPrincipal();
        model.addAttribute("username",principal.getUsername());
        return prefix+"/userList";
    }

    @GetMapping("/home")
    public String Home(Model model){
        SecurityContext context= SecurityContextHolder.getContext();
        System.out.println("userDetails:"+context);
        Authentication authentication=context.getAuthentication();
        UserDetails principal=(UserDetails)authentication.getPrincipal();
        model.addAttribute("username",principal.getUsername());
        return prefix+"/home";
    }

    @GetMapping("/ticketList")
    public String ticketList(Model model){
        SecurityContext context= SecurityContextHolder.getContext();
        System.out.println("userDetails:"+context);
        Authentication authentication=context.getAuthentication();
        UserDetails principal=(UserDetails)authentication.getPrincipal();
        model.addAttribute("username",principal.getUsername());
        return prefix+"/ticketList";
    }

        @GetMapping("/ticketcheck")
        public String ticketCheck(Model model){
            SecurityContext context= SecurityContextHolder.getContext();
            System.out.println("userDetails:"+context);
            Authentication authentication=context.getAuthentication();
            UserDetails principal=(UserDetails)authentication.getPrincipal();
            model.addAttribute("username",principal.getUsername());
            return prefix+"/ticketCheck";
    }

    @GetMapping("/userban")
    public String userBan(Model model){
        SecurityContext context= SecurityContextHolder.getContext();
        System.out.println("userDetails:"+context);
        Authentication authentication=context.getAuthentication();
        UserDetails principal=(UserDetails)authentication.getPrincipal();
        model.addAttribute("username",principal.getUsername());
        return prefix+"/userBan";
    }

    @GetMapping("/userauthority")
    public String userAuthority(Model model){
        SecurityContext context= SecurityContextHolder.getContext();
        System.out.println("userDetails:"+context);
        Authentication authentication=context.getAuthentication();
        UserDetails principal=(UserDetails)authentication.getPrincipal();
        model.addAttribute("username",principal.getUsername());
        return prefix+"/authorityList";
    }

    @GetMapping("/fileTicket")
    public String FileTicket(Model model){
        SecurityContext context= SecurityContextHolder.getContext();
        System.out.println("userDetails:"+context);
        Authentication authentication=context.getAuthentication();
        UserDetails principal=(UserDetails)authentication.getPrincipal();
        model.addAttribute("username",principal.getUsername());
        return prefix+"/fileList";
    }
}
